<?php
include_once("../include/common.inc.php");
include_once('../comm.php');
if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
    $jpg = $GLOBALS['HTTP_RAW_POST_DATA'];
    $w = $_GET['w'];
    $h = $_GET['h'];
    //header("Content-Type: image/jpeg");
    //header("Content-Disposition:attachment;filename=".$img);
    //echo $jpg;
    // 用户登录则取UID，否则统一为0:无主文件
    $uid = isset($_COOKIE['DedeUserID'])?$_COOKIE['DedeUserID']:0;
    $filename1 = time();
    $filename = $filename1.'.jpg';
    $path = $fm_rootdir.'/uploads/maked/'.$uid.'/';
    // 用户目录不存在则创建
    $dir1 = '/uploads/maked/'.$uid.'/';
    $dir2 = '..'.'/uploads/maked/'.$uid.'/';
    if(!is_dir($dir2)){
        mkdir($dir2);
        //echo 'mkdir '.$dir2.' is ok';
    }
    //文件是否可写
    $fhandle = $path.$filename;
    if(!$handle = fopen($fhandle,'wb')){
        //print   "不能打开文件   $fhandle";
        echo 'FALSE';
        exit;
    }
    //   将$somecontent写入到我们打开的文件中。  
    if(!fwrite($handle,$jpg)){
        //print   "不能写入到文件   $fhandle";  
        echo 'FALSE';
        exit;
    }
    //print "成功地将   $somecontent   写入到文件$filename";  
    //echo 'TRUE';
    fclose($handle);

    //保存进数据库
    $f1 = $dir1.$filename;
    $inquery = "INSERT INTO `fmmaked`(uid,url,memo,width,height)
            VALUES('$uid','$f1','$filename1','$w','$h')";
    $re = $dsql->ExecuteNoneQuery($inquery);
    if($re){
        echo 'OK';
    }else{
        echo 'FALSE';
    }

}else {
    echo "FALSE";
}
?>